\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exercises}[2024/03/29 exercises class]

\RequirePackage{xkeyval}
\newif\ifslide
\DeclareOptionX{slide}{\slidetrue}
\DeclareOptionX*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptionsX*\relax
\LoadClass{article}

\RequirePackage{geometry}
\ifslide
  \geometry{paperwidth=126mm,paperheight=96mm,hmargin={1.5em,1em},vmargin={1em,1em}}
\else
  \geometry{b5paper,margin=6em}
\fi
\geometry{marginparsep=2pt,marginparwidth=5em}

\RequirePackage{microtype,ifthen,minted}
%\RequirePackage{mparhack} % marginpar 有时给出的位置不对，这是个修正

\RequirePackage[
  backend=biber,
  hyperref=true,
  doi=true,
  style=gb7714-2015,
  gbnamefmt=lowercase
]{biblatex}
%\renewcommand{\cite}[2][]{\parencite{#2}\ifthenelse{\equal{#1}{}}{}{~#1}}
\addbibresource{../inputs/main.bib}

%%%% 字体设置
\RequirePackage{fontspec,xunicode,xltxtra,xeCJK}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
\setmainfont{NewComputerModern10}
%\setmainfont{XITS}
%\setsansfont{Merriweather Sans Light}[BoldFont={Merriweather Sans},Numbers=Lowercase]
\setsansfont[BoldFont=Myriad Pro]{Myriad Pro Light}
\setmonofont[Scale=0.9]{DejaVu Sans Mono}
\setCJKmainfont[
    BoldFont=FZYaSong-DB-GBK,
    ItalicFont=STKaiti,
]{FZShuSong-Z01S}
\setCJKsansfont[BoldFont=Noto Sans CJK SC]{Noto Sans CJK SC Light}
\setCJKmonofont[Scale=0.9]{FZZhunYuan-M02}
\newcommand\songti{\CJKfontspec{FZShuSong-Z01S}}
\newcommand\heiti{\CJKfontspec{SimHei}}
\newcommand\xinwei{\CJKfontspec{STXinwei}}
\newcommand\fangsong{\CJKfontspec{STFangsong}}
\newcommand\kaiti{\CJKfontspec{STKaiti}}
\newcommand\lishu{\CJKfontspec{STLiti}}
\newcommand\xingkai{\CJKfontspec{STXingkai}}
\newcommand{\yuanti}{\CJKfontspec{FZZhunYuan-M02}}

% 数学设定
\RequirePackage{amsmath,amsthm,unicode-math,mathtools,stmaryrd,multicol,xcolor,extarrows}
\unimathsetup{math-style=TeX}
\setmathfont{NewComputerModernMath}
\setmathfont[range=cal]{NewComputerModernMath}
%\setmathfont{XITS Math}
%\setmathfont{XITS Math}[range=cal]
\setmathfont[range=scr]{XITS Math}

\setlength\multicolsep{\topsep}
\RequirePackage{array}   % for \newcolumntype macro
\newcolumntype{L}{>{$}l<{$}} % math-mode version of "l" column type
\newcolumntype{R}{>{$}r<{$}} 
\newcolumntype{C}{>{$}c<{$}} 
\renewcommand{\arraystretch}{1.2}


\newcounter{chapter}
\counterwithin{section}{chapter}

\numberwithin{equation}{section}
%%%%theorem style
\newtheoremstyle{plainzh}% name
{.5em}% Space above
{.5em}% Space below 
{\kaiti}% Body font
{}% Indent amount
{\bfseries}% Theorem head font
{.}% Punctuation after theorem head 
{.5em}% Space after theorem head 
{}% Theorem head spec (can be left empty, meaning ‘normal’ )
\newtheoremstyle{definitionzh}{.5em}{.5em}{}{}{\bfseries}{.}{.5em}{}
\theoremstyle{plainzh}
\newtheorem*{theorem*}{定理}
\newtheorem{theorem}{定理}
\newtheorem{observation}[theorem]{观察}
\newtheorem{promise}[theorem]{承诺}
\newtheorem{proposition}[theorem]{命题}
\newtheorem*{proposition*}{命题}
\newtheorem{problem}[theorem]{难题}
\newtheorem{question}[theorem]{问题}
\newtheorem{conjecture}[theorem]{猜想}
\newtheorem{corollary}[theorem]{推论}
\newtheorem*{corollary*}{推论}
\newtheorem{assertion}[theorem]{论断}
\newtheorem{lemma}[theorem]{引理}
\newtheorem*{lemma*}{引理}
\newtheorem*{claim}{断言}
\theoremstyle{definitionzh}
\newtheorem{definition}[theorem]{定义}
\newtheorem*{notation}{记号}
\newtheorem{example}[theorem]{例}
\newtheorem*{note*}{注}
\renewcommand\proofname{证明}
\newenvironment{solution}{
    \renewcommand\proofname{解答}\begin{proof}
}{\end{proof}\renewcommand\proofname{证明}}
\newtheorem{exercise}{}
\counterwithin{exercise}{chapter}
\theoremstyle{definitionzh}
\newtheorem{remark}{注记}[exercise]
\newtheorem*{remark*}{注记}
\newtheoremstyle{exercise*}{3pt}{3pt}{}{}{\bfseries}{.}{.5em}{#3}
\theoremstyle{exercise*}
\newtheorem*{exercise*}{}

\newtheorem{addendum}{}[exercise]
\RequirePackage{titling}

% utf 符号
\RequirePackage{utfsym, chemformula}
\RequirePackage{marginnote}
%\reversemarginpar  % 为了把考试相关的题目标出来
\newcommand{\gouxuan}{{\color{red}\usym{2713}}}
\newcommand{\marked}{\reversemarginpar\marginnote{\gouxuan}\normalmarginpar}
\newcommand{\tiyuan}[1]{\normalmarginpar\marginnote{#1}}

\RequirePackage{titlesec}
\newcommand{\periodafter}[1]{#1.}
\titleformat{\section}{\center\normalsize\bfseries\Large\sffamily}{\@Alph\c@section.}{.5em}{}
\titleformat{\paragraph}{\bfseries}{\large\theparagraph.}{.5em}{}

\newcommand{\Azu}{\section{作业题}}
\newcommand{\Bzu}{\section{补充题与考研题}}
\newcommand{\Czu}{\section{杂题}}

% 用于定义星号版本的命令
\RequirePackage{suffix}


% 用于忽略
\newcommand\aemph[1]{{\fangsong #1}}
\newcommand\hint{\par\noindent \textbf{提示.} }
\RequirePackage{zhnumber}

\newcounter{fangfa}
\counterwithin*{fangfa}{exercise}
\newcommand\fangfa{%
  \addtocounter{fangfa}{1}%
  \noindent\framebox{\kaiti 方法\zhnumber{\thefangfa}}~%
}
\WithSuffix\newcommand\fangfa*{%
  \addtocounter{fangfa}{1}%
  \noindent\starmark\framebox{\kaiti 方法\zhnumber{\thefangfa}}~%
}
% 给习题打星号: https://tex.stackexchange.com/questions/123392/add-a-marker-to-the-left-of-the-text
\newcommand{\starmark}{\strut\vadjust{\domark}}
\newcommand{\domark}{%
  \vbox to 0pt{
    \kern-\dp\strutbox
    \hbox{\smash{\llap{*\kern.1em}}}
    \vss
  }%
}
\RequirePackage[export]{adjustbox}
\graphicspath{ {../images}}


%%%% 列表
\RequirePackage[shortlabels]{enumitem}
\setlist{parsep=0em,itemsep=3pt,partopsep=0em,topsep=1ex}
\setlist[enumerate,1]{
    listparindent=0em,
    label=\textup{(\arabic*)},
    labelindent=0em,
    itemindent=0em,
    widest,
    align=parleft,
    leftmargin=2em,
    labelsep=*,
}
\setlist[enumerate,2]{
    listparindent=0em,
    label=\textup{(\roman*)},
    labelindent=0em,
    itemindent=0em,
    widest,
    align=parleft,
    leftmargin=2em,
    labelsep=*,
}

\setlength{\parindent}{2em}

%%%% 图片
\RequirePackage{graphicx,tikz,pgfplots,subcaption}
\renewcommand{\figurename}{图}
\usetikzlibrary{
  cd,arrows.meta,calc,matrix,
  petri,positioning,decorations,
  decorations.pathreplacing,pgfplots.fillbetween,
  decorations.markings,intersections,
  calligraphy,shapes.geometric,
}
\tikzset{>=Computer Modern Rightarrow}

\RequirePackage{hyperref}
\hypersetup{	
    bookmarks=true,
    unicode=true,
    psdextra,
    colorlinks=true,
    pdfborder={0,0,0},
}


\input{symbols.sty}
\renewcommand{\norm}[1]{|#1|}
\renewcommand{\Norm}[1]{\left|#1\right|}
\renewcommand{\pair}[1]{\left(#1\right)}

\RequirePackage{datetime}
\newdateformat{mydate}{\THEYEAR 年 \THEMONTH 月 \THEDAY 日}
\author{sc@hsu.edu.cn}
\date{\mydate\today}

\newcommand{\extitle}[3][]{
\ifthenelse{\equal{#1}{}}{
\title{\Huge\bfseries\sffamily 第 #2 章\quad #3}\setcounter{chapter}{#2}\setcounter{section}{-1}\stepcounter{section}}
  {\title{\Huge\bfseries\sffamily 参考答案}\setcounter{chapter}{#2}\setcounter{section}{-1}\stepcounter{section}}
\maketitle
}


% 横线：第一个参数是长度（无词时填空用的下划线），第二个参数是词
% 如果有词就是在词下面划线，如果无词就是划指定长度的填空用的下划线
\RequirePackage{ulem}
\newcommand\hengxian[2]{%
  \ifthenelse{\equal{#2}{}}{%
    \uline{\phantom{\hspace{#1}}}%
  }{%
    \uline{\phantom{\hspace{.3em}}#2\phantom{\hspace{.3em}}}%
  }%
}

\renewcommand{\emph}[1]{{\kaiti #1}}

% 填空的括号和选择的横线
\newcommand\xuanxiang{\ignorespaces （\hspace{1em}）}
\newcommand\tiankong{\ignorespaces \hengxian{1.5cm}{}}

% 用于一行两个选项或四个选项
\newcommand{\twochoice}[2]{%
\par\noindent\parbox{0.5\columnwidth}{#1}%
\parbox{0.5\columnwidth}{#2}}
\newcommand{\threechoice}[3]{\par\noindent\parbox{0.333\columnwidth}{#1}%
\parbox{0.333\columnwidth}{#2}%
\parbox{0.333\columnwidth}{#3}}
\newcommand{\fourchoice}[4]{%
\par\noindent\parbox{0.25\columnwidth}{#1}%
\parbox{0.25\columnwidth}{#2}%
\parbox{0.25\columnwidth}{#3}%
\parbox{0.25\columnwidth}{#4}
}

\AtEndDocument{
  \wlog{习题总数：\arabic{exercise}}
}
